package com.jdls.web;

import com.jdls.pojo.Brand;
import com.jdls.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 嘉德罗斯
 * @date 2021/8/31
 */
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8"); // 处理请求参数的乱码
        response.setContentType("text/html;charset=utf-8"); // 处理响应数据的乱码
        Brand brand = new Brand();
        String id = request.getParameter("id");
        String brandName = request.getParameter("brandName");
        String companyName = request.getParameter("companyName");
        String ordered1 = request.getParameter("ordered");
        String description = request.getParameter("description");
        String status1 = request.getParameter("status");
        int ordered = Integer.parseInt(ordered1);
        int status = Integer.parseInt(status1);
        int i = Integer.parseInt(id);
        brand.setId(i);
        brand.setBrandName(brandName);
        brand.setCompanyName(companyName);
        brand.setOrdered(ordered);
        brand.setDescription(description);
        brand.setStatus(status);
        BrandService service = new BrandService();
        service.update(brand);
        response.sendRedirect("/maven/SelectAllServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
